/* eslint-disable eqeqeq */
import actionInfo from '../action'
import { productnameAdd, productnameQuery } from '../service/productnameService'

function productnameInfoReducer(state = { productnameList: [] }, action) {
    switch (action.type) {
        case actionInfo.productname.ADD:
            return { productnameList: [...state.productnameList, action.payload] }
        case actionInfo.productname.QUERY:
            return { productnameList: action.payload }
        default:
            return state
    }
}
export const asyncProductnameQuery = (params) => async (dispatch) => {
    let { data } = await productnameQuery(params);//做异步请求
    dispatch(productnameInfoQuery(data.msg));//
}
const productnameInfoQuery = (payload) => {
    return {
        type: actionInfo.productname.QUERY,
        payload
    }
}
export const asyncProductnameAdd = (params) => async (dispatch) => {
    let { data } = await productnameAdd(params);//做异步请求
    if (data.code == 1) {
        dispatch(productnameInfoAdd(data.msg));
    }
}
const productnameInfoAdd = (payload) => {
    return {
        type: actionInfo.productname.ADD,
        payload
    }
}
export default productnameInfoReducer